<template>
  <div>
    <TopFilter labelWidth="110" :list="topFilterList" :collapse="false" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      datakey="records"
      :onColumnsChange="columns => (this.columns = columns)"
      :onSyncTableData="tableChangeFun"
      :onRowSelectChange="selectChange"
    >
    </FilterTable>

    <div class="dialogBottmView">
      <el-button size="small" type="primary" class="btnStyle" @click="submitBtn">确定 </el-button>
      <el-button size="small" type="primary" class="btnStyle" @click="closeDialog">关闭 </el-button>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex';
import { dictionary } from '@/utils/dictMixin';
import moment from 'moment';
import { isEmpty } from '@/utils/utils';
import { getLabourItemList } from '@/api/repair/batchEventManagement/activityDistribution';

export default {
  name: 'addVin',
  components: {},
  mixins: [dictionary],
  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createTopFilterList(),
      visible: false,
      fetchApi: getLabourItemList,
      fetchParams: {},
      columns: this.createTableColumns(),
      selectArr: []
    };
  },
  components: {},

  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    tableChangeFun(val) {
      console.log(val, 'val');
      // val.forEach(obj => {
      //   obj.labourPrice = 120;
      // });
    },
    selectChange(val) {
      this.selectArr = val;
      this.selectArr.forEach(item=>{
        item.costType = 58031002
      })
      console.log(val);
    },

    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },

        {
          title: '维修工时代码',
          dataIndex: 'labourCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '维修工时名称',
          dataIndex: 'labourName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '索赔工时',
          dataIndex: 'stdLabourHour',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        // {
        //  title: '车系',
        //  dataIndex: 'seriesCode',
        //  sorter: true,
        //  filter: true,
        //  filterType: 'input',
        // },
        {
         title: '车型',
         dataIndex: 'modelLabourName',
         sorter: true,
         filter: true,
         filterType: 'input',
        },
      ];
    },
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '维修工时代码',
          fieldName: 'labourCode',
          placeholder: '维修工时代码...'
        },
        {
          type: 'INPUT',
          label: '维修工时名称',
          fieldName: 'labourName',
          placeholder: '维修工时名称...'
        }
      ];
    },

    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },

    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);

      console.log(this.fetchParams);
    },

    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    closeDialog() {
      this.$emit('closeVin');
    },
    submitBtn() {
      if (this.selectArr.length == 0) {
        this.$notify.warning({ title: '提示信息', message: '请您选择维修项目' });
        return;
      }
      this.$emit('selectArr', this.selectArr);
    }
  }
};
</script>

<style lang="less" scoped>
.bg1 {
  border: 1px solid @borderColor;
  border-radius: @borderRadius;
  box-shadow: @boxShadow;
  padding: @modulePadding;
  padding-left: 0;
  padding-top: 15px;
  padding-bottom: 15px;
}

.bg2 {
  margin-top: 10px;
  margin-bottom: 10px;
}

.btn {
  text-align: center;
}

.btnStyle {
  margin-top: 10px;
}
</style>
